pragma License (GPL);
--
-- drk-bigint.ads
--
-- Copyright (C) 2012 - Thibault BUREL
--
-- This file is part of DRK.BigRat.
--
-- DRK.BigRat is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- DRK.BigRat is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with DRK.BigRat.  If not, see <http://www.gnu.org/licenses/>
--
with Ada.Containers.Doubly_Linked_Lists;

with System;

package DRK.BigInt is

   pragma Preelaborate (DRK.BigInt);

   type Instance is private;

   ----------------------
   --  Init functions  --
   ----------------------

   function Init (Value : in Natural) return Instance;

   function Init_Pow_10 (Exp : in Natural) return Instance;
   --  This function returns a new bigrat computed by 10^Exp.

   ----------------------------
   --  Comparison functions  --
   ----------------------------

   --  WARNING ! Due to an implementation choice, the comparison function will
   --  not return the right answer if any parameter has leading 0 digit in its
   --  mantissa.
   --  This warning does not concern users of this package since leading 0
   --  digits are suppressed by algorithms. However, developpers who want
   --  extend this package must pay attention to suppress leading 0 digits.
   function "="  (Left, Right : in Instance) return Boolean;
   function "<"  (Left, Right : in Instance) return Boolean;
   function ">"  (Left, Right : in Instance) return Boolean;
   function "<=" (Left, Right : in Instance) return Boolean;
   function ">=" (Left, Right : in Instance) return Boolean;

   ------------------------
   --  Binary operators  --
   ------------------------

   function "+" (Left, Right : in Instance) return Instance;
   function "-" (Left, Right : in Instance) return Instance;
   function "*" (Left, Right : in Instance) return Instance;
   function "/" (Left, Right : in Instance) return Instance;

   ----------------------------
   --  Arithmetic functions  --
   ----------------------------
   function Remainder (Left, Right : in Instance) return Instance;

   function GCD (First, Second : in Instance) return Instance;

   -------------------------------
   --  Miscellaneous functions  --
   -------------------------------

   function Digit_Size return Natural;
   --  Return the size in bits of a digit. The digit size will depends both of
   --  the hardware and the compiler.

   Underflow : exception;

private

   type    Chunck is mod System.Max_Binary_Modulus;
   subtype Carry  is Chunck range 0 .. 1;

   package Digit_List
   is new Ada.Containers.Doubly_Linked_Lists (Element_Type => Chunck,
                                              "="          => "=");

   type Instance is record
      Mantissa : Digit_List.List;
   end record;

end DRK.BigInt;
